package com.lyl.projectspringboot.controller;

import com.lyl.projectspringboot.dto.LoginDto;
import com.lyl.projectspringboot.dto.UserDto;
import com.lyl.projectspringboot.dto.UserRegisterDto;
import com.lyl.projectspringboot.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@RequestMapping("/login")
public class LoginController {

    private final UserService userService;

    //用户登录
    @PostMapping("/userLogin")
    public String login(@RequestBody LoginDto loginDto) {

        boolean login = userService.userLogin(loginDto);

        if (login) {
            return "登录成功";
        } else {
            return "登录失败，账号或者密码错误";
        }
    }
    //用户注册
    @PostMapping("/userRegister")
    public String register(@RequestBody UserRegisterDto userRegisterDto) {

        boolean register = userService.UserRegister(userRegisterDto);

        if (register) {
            return "注册成功";
        } else {
            return "注册失败，账号已存在";
        }
    }


}
